package com.huaxin.hxmodulesystem.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaxin.hxmodulesystem.dto.ResponseResult;
import com.huaxin.hxmodulesystem.dto.request.AddFamilyReqDTO;
import com.huaxin.hxmodulesystem.dto.request.UpdateFamilyReqDTO;
import com.huaxin.hxmodulesystem.dto.response.GetFamilyListRespDTO;
import com.huaxin.hxmodulesystem.models.Family;
import com.huaxin.hxmodulesystem.service.FamilyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "家庭")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/sys/family")
public class FamilyController {
    private final FamilyService familyService;

    /**
     * 添加家庭
     *
     * @param in
     * @return
     */
    @Operation(summary = "添加家庭", description = "添加家庭")
    @PostMapping("/addFamily")
    public ResponseResult<String> addFamily(@RequestBody AddFamilyReqDTO in) {
        return familyService.addFamily(in);
    }

    /**
     * 修改家庭
     *
     * @param in
     * @return
     */
    @Operation(summary = "修改家庭", description = "修改家庭")
    @PostMapping("/updateFamily")
    public ResponseResult<String> updateFamily(@RequestBody UpdateFamilyReqDTO in) {
        return familyService.updateFamily(in);
    }

    /**
     * 删除家庭
     *
     * @param id
     * @return
     */
    @Operation(summary = "删除家庭", description = "删除家庭")
    @GetMapping("/deleteFamily")
    public ResponseResult<String> deleteFamily(@Parameter(name = "id", description = "家庭ID") @RequestParam(value = "id", required = true) String id) {
        return familyService.deleteFamily(id);
    }

    /**
     * 获取家庭列表
     *
     * @param userId 用户ID
     * @return
     */
    @Operation(summary = "获取家庭的用户列表", description = "获取家庭的用户列表")
    @GetMapping("/getFamilyTheUserList")
    public ResponseResult<GetFamilyListRespDTO> getFamilyTheUserList(@Parameter(description = "用户ID", name = "userId", required = true) @RequestParam(name = "userId", required = true) String userId) {
        return familyService.getFamilyTheUserList(userId);
    }

    @Operation(summary = "获取家庭列表", description = "获取家庭列表")
    @GetMapping("/getFamilyList")
    public ResponseResult<Page<Family>> getFamilyList(@Parameter(description = "页码", name = "pageNum", required = true) @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                                      @Parameter(description = "页大小", name = "pageSize", required = true) @RequestParam(name = "pageSize", required = true) Integer pageSize,
                                                      @Parameter(description = "名称", name = "name") @RequestParam(name = "name", required = false) String name) {
        return familyService.getFamilyList(pageNum, pageSize, name);
    }

    /**
     * 添加家庭成员
     *
     * @param userId
     * @param familyId
     * @return
     */
    @Operation(summary = "添加家庭成员", description = "添加家庭成员")
    @GetMapping("/addFamilyMember")
    public ResponseResult<String> addFamilyMember(@Parameter(description = "用户id", name = "userId") @RequestParam(name = "userId", required = true) String userId,
                                                  @Parameter(description = "家庭id", name = "familyId") @RequestParam(name = "familyId", required = true) String familyId) {
        return familyService.addFamilyMember(userId, familyId);
    }

    /**
     * 移除家庭成员
     *
     * @param userId
     * @param familyId
     * @return
     */
    @Operation(summary = "移除家庭成员", description = "移除家庭成员")
    @GetMapping("/removeFamilyMember")
    public ResponseResult<String> removeFamilyMember(@Parameter(description = "用户ID", required = true, name = "userId") @RequestParam(name = "userId", required = true) String userId,
                                                     @Parameter(description = "家庭ID", required = true, name = "familyId") @RequestParam(name = "familyId", required = true) String familyId) {
        return familyService.removeFamilyMember(userId, familyId);
    }

    /**
     * 根据家庭id查询家庭信息
     *
     * @param familyId 家庭id
     * @return
     */
    @Operation(summary = "根据家庭id查询家庭信息", description = "根据家庭id查询家庭信息")
    @GetMapping("/getFamilyById")
    public ResponseResult<Family> getFamilyById(String familyId) {
        return familyService.getFamilyById(familyId);
    }
}
